package com.storeroompda.tool;

import android.content.Context;
import android.media.AudioAttributes;
import android.media.MediaPlayer;
import android.media.SoundPool;

import com.storeroompda.R;

public class AudioControl {
    static String tag="AudioControl";
    public static AudioAttributes abs = new AudioAttributes.Builder()
            .setUsage(AudioAttributes.USAGE_MEDIA)
            .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
            .build() ;
    public static SoundPool mSoundPoll = null;


    public static void errorSound(Context context)
    {
//        MediaPlayer mediaPlayer01;
//        mediaPlayer01 = MediaPlayer.create(context, R.raw.cf);
//        mediaPlayer01.start();

        try
        {
            if(mSoundPoll==null)
            {
                mSoundPoll =  new SoundPool.Builder()
                        .setMaxStreams(1000)
                        .setAudioAttributes(abs)
                        .build() ;
                mSoundPoll.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
                    @Override
                    public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
                        soundPool.play(sampleId,(float)1,(float)1,1,0,1);
                    }
                });
            }
            mSoundPoll.load(context,R.raw.cf,1);
        }
        catch (Exception e)
        {
            mSoundPoll.release();
            mSoundPoll=null;
            e.printStackTrace();
        }
    }
}
